package com.tiancheng.trade.settlement.service.order.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.settlement.mapper.order.OrdersMapper;
import com.tiancheng.trade.settlement.model.order.Orders;
import com.tiancheng.trade.settlement.service.order.IOrderService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * 订单信息
 */
@Service
public class OrdersServiceImpl implements IOrderService {

    @Resource
    OrdersMapper ordersMapper;


    @Override
    public Orders findByOrderId(String orderId) {
        return ordersMapper.selectOne(new QueryWrapper<Orders>().eq("order_id", orderId));
    }

    @Override
    public List<Orders> findByOrderIds(List<String> orderIds) {
        if (CollectionUtils.isNotEmpty(orderIds)) {
            return ordersMapper.selectList(new QueryWrapper<Orders>().in("order_id", orderIds));
        }
        return Collections.emptyList();
    }


    @Override
    public PageInfo<Orders> findWechatCouponOrders(LocalDateTime createStart, LocalDateTime createEnd, int currentPage, int pageSize) {
        QueryWrapper<Orders> conditions = new QueryWrapper<>();
        conditions.between("pay_time", createStart, createEnd);
        conditions.eq("pay_status", "AP");
        conditions.eq("is_coupon", 1);
        // 平台金额小于总优惠金额
        return ordersMapper.find(conditions, currentPage, pageSize);
    }
}
